package com.hualan.sfzy.controller;


import com.hualan.sfzy.model.entity.CourseCollect;
import com.hualan.sfzy.service.CourseCollectService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/courseCollect")
public class CourseColllecController {
    @Autowired
    private CourseCollectService courseCollectService;
    @PostMapping()
    public Result addCourseColllect(@RequestBody CourseCollect courseCollect) {
        int result=courseCollectService.add(courseCollect);
        if(result>0){
            return Result.success("新增成功");
        }
        return Result.error("失败");

    }
    @DeleteMapping()
    public Result deleteCourseColllect(@RequestBody CourseCollect courseCollect) {
        int result=courseCollectService.remove(courseCollect);
        if(result>0){
            return Result.success("删除成功");
        }
        return Result.error("失败");
    }
    @GetMapping
    public Result getCourseColllect(@RequestParam int courseid) {
        int result=courseCollectService.selectByCourseId(courseid);
        return Result.success(result);
    }
    @GetMapping("/exit")

    public Result exit( @RequestParam("courseid") int courseId,
                        @RequestParam("userid") int userId) {
        CourseCollect courseCollect=new CourseCollect();
        courseCollect.setCourseid(courseId);
        courseCollect.setUserid(userId);
        int result=courseCollectService.IsExist(courseCollect);
         return Result.success(result);
    }





}
